﻿var viewModel = new function () {
    this.Bcc = ko.observable(returnData.Bcc);
    //this.Body = ko.observable(returnData.Body.replace(/\r\n/g, "<br />"));
    this.Cc = ko.observable(returnData.Cc);
    this.From = ko.observable(returnData.From);
    this.Subject = ko.observable(returnData.Subject);
    this.Title = ko.observable(returnData.Title);
    this.To = ko.observable(returnData.To);
    $("#bodyContent").html(returnData.Body.replace(/\r\n/g, "<br />"));
};

ko.applyBindings(viewModel, document.getElementById("emailPreviewHtml"));

function ReturnSetupWizard() {
    /*var idTemplate = getURLParameter('id').toString();
    if (idTemplate == 'null')
    else {
        var link = "/SetUpWizard" + "?step=2";
        window.location = link;
        document.location = link;
    }*/
}
function ReturnEmail() {
    var link = "/Email";
    window.location = link;
    document.location = link;

}
function getIndexById(id, searchListFilter) {
    for (var i = 0; i < searchListFilter.length; i++) {
        if (searchListFilter[i].ID == id) {
            return i;
        }
    }
}
// Get URL parameter by name
function getURLParameter(name) {
    return decodeURIComponent((location.search.match(RegExp("[?|&]" + name + '=(.+?)(&|$)')) || [, null])[1]);
}
function PrintEmailPreview() {
    var panel = document.getElementById("emailPreviewHtml").innerHTML;
    var printWindow = window.open('', '', 'left=0,top=0,width=870,height=680,toolbar=0,scrollbars=1,status=0');
    panel = panel.replace('return PrintEmailPreview();', 'window.print();');
    
    printWindow.document.write('<!DOCTYPE html>');
    printWindow.document.write('<html class="popup-w popup-w-blue">');
    printWindow.document.write('    <head>');
    printWindow.document.write('        <meta charset="utf-8" />');
    printWindow.document.write('        <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" /> ');
    printWindow.document.write('        <link href="/Content/global.css" rel="stylesheet" type="text/css" /> ');
    printWindow.document.write('        <script type="text/javascript" src="/Scripts/jquery-1.7.2.min.js"></script> ');
    printWindow.document.write('    </head>');
    printWindow.document.write('    <body>');
    printWindow.document.write('        <div id="emailPreviewHtml">');
    printWindow.document.write(panel);
    printWindow.document.write('        </div>');
    printWindow.document.write('    </body>');
    printWindow.document.write('    <script>');
    printWindow.document.write('        $("a.btn-close-small").replaceWith("");');
    printWindow.document.write('    </script>');
    printWindow.document.write('</html>');

    printWindow.document.close();
    setTimeout(function () {
        printWindow.print();
    }, 500);
    return false;
}